
package org.jetnuke.modules.blog;

import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.apache.xmlrpc.XmlRpcServer;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.modules.blog.utils.PingBackHandler;

public class PingBack_RPC_XML implements IAction {

	
	
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		XmlRpcServer xmlRpcServer=new XmlRpcServer();
		xmlRpcServer.addHandler("$default",new PingBackHandler(request));	
		byte[] result = xmlRpcServer.execute(request.getInputStream());
		response.setContentType("text/xml");
		response.setContentLength(result.length);
		OutputStream outStream = response.getOutputStream();
		outStream.write(result);
		outStream.flush();
		return null;
	}
	
}
